package com.yang.controller.admin;

import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.yvo.*;
import com.yang.service.admin.AdminOrderService;
import com.yang.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 杨庆
 * @since: 2022.9.7 14:22
 * @description:
 */
@RestController
@RequestMapping("admin/order")
public class AdminOrderController {

    @Autowired
    AdminOrderService adminOrderService;


    /**订单首页显示 /admin/order/channel
     * @description:
    []
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.7 14:25
     */
    @RequestMapping("channel")
    public BaseRespVo channel() {
        //返回的是一个集合
        return BaseRespVo.ok(Constant.CLIST);
    }

    /**
    * @description:  显示所有的订单
    [orderLIstBO]
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.7 19:56
     */
    @RequestMapping("list")
    public BaseRespVo listOrder(OrderLIstBO orderLIstBO){
        CommonData commonData  = adminOrderService.selectAll(orderLIstBO);
        return BaseRespVo.ok(commonData);
    }

    /**
    * @description: 根据订单的id查询
    [id]
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.7 19:57
     */

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        OrderDetailVO orderDetailVO = adminOrderService.selectById(id);
        return BaseRespVo.ok(orderDetailVO);
    }


    /**
    * @description: 发货
    []
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.7 19:57
     */
    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody ShipBO shipBO){
        int code  = adminOrderService.ship(shipBO);
        if (code == 200) {
            return BaseRespVo.ok(shipBO);
        } else if (code == 404) {
            return BaseRespVo.error("失败");
        }
        return BaseRespVo.ok(shipBO);
    }

    /**
    * @description: 订单的删除
    []
    * @return: com.yang.bean.common.BaseRespVo
    * @author: 杨庆
    * @time: 2022.9.7 20:14
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody DeleteOrderBO deleteOrderBO){
        Integer orderId = deleteOrderBO.getOrderId();
        adminOrderService.delete(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody OrderReplyBO orderReplyBO) {
        //{"commentId":1019,"content":"111"}
        BaseRespVo reply = adminOrderService.reply(orderReplyBO);
        return reply;
    }
}
